package com.zhuiyun.pm.client.address.mapper;

import com.zhuiyun.pm.client.address.entity.ClientAddress;
import com.zhuiyun.pm.config.BaseMapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AddressMapper extends BaseMapper<ClientAddress> {

    /**
     * 地址删除方法
     * @param id
     * @return
     */
    @Update("update client_address set del_flag = 1 where id = #{id}")
    int delAddressInfo(int id);


    /**
     * 用户和地址表连查查询每个买家的地址
     * @author 温
     * @date 2023/3/16 13:37
     * @parameter [clientAddress]
     * @return java.util.List<com.zhuiyun.pm.client.dizhi.entity.ClientAddress>
     */
    @Select("select* from client_address where user_id = #{userId}")
    @Results({
            @Result(property = "consigneeName" , column = "consignee_name"),
            @Result(property = "clientAddress" , column = "client_address"),
            @Result(property = "clientPhone" , column = "client_phone"),
            @Result(property = "clientEconomize" , column = "client_economize"),
            @Result(property = "clientCity" , column = "client_city"),
            @Result(property = "userId" , column = "user_id"),
            @Result(property = "clientCounty" , column = "client_county"),
            @Result(property = "regionType" , column = "region_type"),
            @Result(property = "delFlag" , column = "del_flag"),
            @Result(property = "detailedAddress" , column = "detailed_address")
    })
    List<ClientAddress> clientAddressList(ClientAddress clientAddress);
    @Select("select b.* from client_user a left join client_address b on a.user_default_addr_id = b.id where a.id = #{userId}")
    @Results({
            @Result(property = "consigneeName" , column = "consignee_name"),
            @Result(property = "clientAddress" , column = "client_address"),
            @Result(property = "clientPhone" , column = "client_phone"),
            @Result(property = "clientEconomize" , column = "client_economize"),
            @Result(property = "clientCity" , column = "client_city"),
            @Result(property = "userId" , column = "user_id"),
            @Result(property = "clientCounty" , column = "client_county"),
            @Result(property = "regionType" , column = "region_type"),
            @Result(property = "delFlag" , column = "del_flag"),
            @Result(property = "detailedAddress" , column = "detailed_address")
    })
    ClientAddress getDefaultAddByUserId(ClientAddress clientAddress);
}
